##import rdflib
##import rdfextras
##
####rdflib.plugin.register('sparql', rdflib.query.Processor, 'rdfextras.sparql.processor', 'Processor')
####rdflib.plugin.register('sparql', rdflib.query.Result, 'rdfextras.sparql.query', 'SPARQLQueryResult')
##
###Choose the Ontology
##ontology = "http://xmlns.com/foaf/0.1/"
##
###Create a WorkSpace
##g=rdflib.ConjunctiveGraph()
##
###Load the Ontology
##g.parse(ontology)
##
##print len(g)
##
##for a in g:
##    print a
##
###Get Ready SPARQL Querying
import SPARQLWrapper

sparql = SPARQLWrapper.SPARQLWrapper("http://lod.openlinksw.com/sparql")
sparql.setQuery("""
PREFIX drugbank: <http://www4.wiwiss.fu-berlin.de/drugbank/resource/drugbank/>
SELECT DISTINCT * WHERE {
?d drugbank:primaryAccessionNo "DB00001".
?d ?p ?o.
}
LIMIT 10
""")
sparql.setReturnFormat(SPARQLWrapper.JSON)



results = sparql.query().convert()

#print results

for result in results["results"]["bindings"]:
    print "Next Result:"
    for k,v in result.iteritems():
        print k,v['value']

